#pragma once
#include<iostream>
#include <cstdio>
#include <cstdarg>
#include <ctime>
#include <string>

#define DEBUG 0
#define NORMAL 1
#define WARNING 2
#define ERROR 3
#define FATAL 4

#define LOGFILE "./calculator.log"

const char* g_val[]=
{
    "DEBUG",
    "NORMA",
    "WARNING",
    "ERROR",
    "FATA"

};

void logMessage(int level,const char* format,...)
{
    char stuBuffer[64];
    time_t timestamp=time(nullptr);//获得时间戳
    snprintf(stuBuffer,sizeof(stuBuffer),"[%ld],%s",timestamp,g_val[level]);
    char logBuffer[64];
    //可变参数列表的使用
    va_list args;
    va_start(args,format);
    vsnprintf(logBuffer,sizeof(logBuffer),format,args);
    va_end(args);
    printf("%s %s\n",stuBuffer,logBuffer);
   /*   FILE*fp=fopen(LOGFILE,"a");
    fprintf(fp,"%s %s\n",stuBuffer,logBuffer);
    fclose(fp) */;
 

}